<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>API测试页面</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        .test-section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
        .test-button { padding: 10px 15px; margin: 5px; background: #007bff; color: white; border: none; border-radius: 3px; cursor: pointer; }
        .test-button:hover { background: #0056b3; }
        .result { margin-top: 10px; padding: 10px; background: #f8f9fa; border-radius: 3px; white-space: pre-wrap; }
        .success { background: #d4edda; color: #155724; }
        .error { background: #f8d7da; color: #721c24; }
    </style>
</head>
<body>
    <h1>任务安排API测试页面</h1>
    
    <div class="test-section">
        <h3>1. 测试获取任务列表</h3>
        <button class="test-button" onclick="testGetList()">获取任务列表</button>
        <div id="listResult" class="result"></div>
    </div>
    
    <div class="test-section">
        <h3>2. 测试获取老人列表</h3>
        <button class="test-button" onclick="testGetElderly()">获取老人列表</button>
        <div id="elderlyResult" class="result"></div>
    </div>
    
    <div class="test-section">
        <h3>3. 测试获取护理项目列表</h3>
        <button class="test-button" onclick="testGetItems()">获取护理项目列表</button>
        <div id="itemsResult" class="result"></div>
    </div>
    
    <div class="test-section">
        <h3>4. 测试获取用户列表</h3>
        <button class="test-button" onclick="testGetUsers()">获取用户列表</button>
        <div id="usersResult" class="result"></div>
    </div>

    <script>
        const API_BASE = 'http://localhost:8080';
        
        async function makeRequest(url, options = {}) {
            try {
                const response = await fetch(url, {
                    headers: {
                        'Content-Type': 'application/json',
                        ...options.headers
                    },
                    ...options
                });
                
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                
                return await response.json();
            } catch (error) {
                console.error('Request failed:', error);
                throw error;
            }
        }
        
        async function testGetList() {
            const resultDiv = document.getElementById('listResult');
            resultDiv.textContent = '正在请求...';
            
            try {
                const data = await makeRequest(`${API_BASE}/system/arrangement/joinList?pageNum=1&pageSize=10`);
                resultDiv.textContent = `成功获取任务列表:\n${JSON.stringify(data, null, 2)}`;
                resultDiv.className = 'result success';
            } catch (error) {
                resultDiv.textContent = `获取任务列表失败: ${error.message}`;
                resultDiv.className = 'result error';
            }
        }
        
        async function testGetElderly() {
            const resultDiv = document.getElementById('elderlyResult');
            resultDiv.textContent = '正在请求...';
            
            try {
                const data = await makeRequest(`${API_BASE}/system/elderly/list?pageNum=1&pageSize=10`);
                resultDiv.textContent = `成功获取老人列表:\n${JSON.stringify(data, null, 2)}`;
                resultDiv.className = 'result success';
            } catch (error) {
                resultDiv.textContent = `获取老人列表失败: ${error.message}`;
                resultDiv.className = 'result error';
            }
        }
        
        async function testGetItems() {
            const resultDiv = document.getElementById('itemsResult');
            resultDiv.textContent = '正在请求...';
            
            try {
                const data = await makeRequest(`${API_BASE}/system/item/list?pageNum=1&pageSize=10`);
                resultDiv.textContent = `成功获取护理项目列表:\n${JSON.stringify(data, null, 2)}`;
                resultDiv.className = 'result success';
            } catch (error) {
                resultDiv.textContent = `获取护理项目列表失败: ${error.message}`;
                resultDiv.className = 'result error';
            }
        }
        
        async function testGetUsers() {
            const resultDiv = document.getElementById('usersResult');
            resultDiv.textContent = '正在请求...';
            
            try {
                const data = await makeRequest(`${API_BASE}/system/user/list?pageNum=1&pageSize=10`);
                resultDiv.textContent = `成功获取用户列表:\n${JSON.stringify(data, null, 2)}`;
                resultDiv.className = 'result success';
            } catch (error) {
                resultDiv.textContent = `获取用户列表失败: ${error.message}`;
                resultDiv.className = 'result error';
            }
        }
    </script>
</body>
</html>
